A. Number 1)frequency of tickets in five boroughs (Manhattan, Kings, The Bronx, State Island, Queens)

violation = read_csv("./Open_Parking_and_Camera_Violations.csv") %>% 
  janitor::clean_names() %>%
  rename(borough = county) %>%  # rename county to borough
  mutate(
    borough = case_when(
      borough %in% c("BK","K", "Kings") ~ "Brooklyn",
      borough %in% c("BX", "Bronx") ~ "Bronx",
      borough %in% c("Q", "QN", "Qns") ~ "Queens",
      borough %in% c("ST", "R", "Rich", "RICH") ~ "State Island",
      borough %in% c("NY", "MN") ~ "Manhattan"),
    issue_date = mdy(issue_date),
    weekday = weekdays(issue_date),
    )  %>%  # make the borough the same 
  filter(borough != "A",                  # get rid of "A"
         weekday !="NA") %>%   # remove data that cannot trun into weekday
  separate(issue_date, into = c("year", "month", "day"), sep = "-")  # separate date into year, month, day
## Rows: 1770806 Columns: 19
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): Plate, State, License Type, Issue Date, Violation Time, Violation,...
## dbl  (7): Summons Number, Fine Amount, Penalty Amount, Interest Amount, Redu...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Warning: 3 failed to parse.
# another potential cleaning 1)select the variables we needed 2)convert the mon into character ?
  
#  frequency_ticket = violation %>% 
#    select(plate, county, issue_date, violation) %>% 
#      mutate(
#      county = case_when(
#        county %in% c("BK","K", "Kings") ~ "Brooklyn",
#        county %in% c("BX", "Bronx") ~ "Bronx",
#        county %in% c("Q", "QN", "Qns") ~ "Queens",
#        county %in% c("ST", "R", "Rich", "RICH") ~ "State Island",
#        county %in% c("NY", "MN") ~ "Manhattan"),
#      issue_date = mdy(issue_date),
#      weekday = weekdays(issue_date)) %>% 
#    filter(county != "A", 
#           weekday != "NA") %>% 
#    separate(issue_date, into = c("year", "month", "day"), sep = "-") %>% 


violation %>% 
  count(borough) %>% 
  mutate(
    borough = fct_reorder(borough, n)) %>% 
  plot_ly(x = ~borough, y = ~n, color = ~borough, type = "bar", colors = "viridis") %>% 
  layout(title = "Frequency of Tickets in Boroughs",
         xaxis = list(title = "Borough"),
         yaxis = list(title = "Number of Tickets"))